using System;
using System.Threading;
using System.Threading.Tasks;
using Godot;

namespace PlayerState
{
public partial class Fall : Node,StateNode
{
    public Player player;
    public PlayerAnimaVfx animaVfx;
    public override void _Ready()
    {
        player = GetNode<Player>("/root/Main/Player");
        animaVfx = player.GetNode<PlayerAnimaVfx>("AnimaVfx");
    }
    
    public void OnEnter()
    {        
        GetNode<AnimatedSprite2D>("../../AnimaPlayer").Animation = "fall";
    }

    public void OnExit()
    {           
    }

    public void OnUpdate(float delta)
    {
        Player player = GetNode<Player>("/root/Main/Player");

        if(player.Health<=0)
            player.SwitchTo("Dead");        
        else if(player.IsOnFloor())
        {
            GetNode<AudioStreamPlayer2D>("Music").Play();
            animaVfx.OnLand(player.GlobalPosition);
            player.SwitchTo("Idle");            
        }
            
    }
}
}
